package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username  string `gorm:"type:varchar(30)"`
	Password  string `gorm:"type:varchar(32)"`
	HeadImage string `gorm:"type:varchar(500)"`
	Age       int64  `gorm:"type:int(11)"`
	NickName  string `gorm:"type:varchar(50)"`
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) FindUserByUsername(db *gorm.DB, username string) error {
	return db.Debug().Where("username = ?", username).FirstOrCreate(u).Error
}
